****************************************************************
*** Hix-Cunningham, "Still Second Order National Elections?"
****************************************************************


****************************************************************
** Data set up
****************************************************************

** Set directory
*cd "[ADD YOUR DIRECTORY NAME]"
cd "/Users/Hix/Library/CloudStorage/Dropbox/WEP 2024 SONE paper/Hix-Cunningham_Dataverse"

** Create log file
log using "ep_sone_log.smcl", replace

** Open datafile
use "ep_sone_dataset.dta", clear

** Generate and name variables
gen gain=vge_ep_ch
gen size=vge_prev_parlgov
gen size_squared=size*size
gen size_cubed=size*size*size
gen size_gov=size*gov
gen gov_early=gov*early
gen mths_prev=days_prev/30
gen mths_prev_squared=mths_prev*mths_prev
gen gov_mths_squared=gov*mths_prev_squared
gen anti_right=anti+right
gen gov_2024=gain if gov==1 & ep10==1
gen opp_2024=gain if gov==0 & ep10==1
label var gov_2024 "Government 2024"
label var opp_2024 "Opposition 2024"
encode country, generate(country_n)

label var gain "Gain"
label var size "Size"
label var size_squared "Size2"
label var size_cubed "Size3"
label var size_gov "Size*Govermment"
label var early_yr1 "Early"
label var gov_early "Government*Early"
label var mths_prev "MonthsSinceElection2"
label var gov_mths_squared "MonthsSinceElection2*Government"
label var gov "Government"
label var new2 "New party"


****************************************************************
* Table 1: Basic second-order national election models
****************************************************************

* Model 1: (Replicating Hix-Marsh 2011, Table A1), pooled for all states, no EP election fixed effects
reg gain size_gov size size_squared size_cubed early gov_early gov new2, cluster(ep_el_n)
eststo sone_basic
outreg2 using "Table1.xls", dec(3) addstat(`r2_a')

* Model 2: Model 1 plus EP election fixed effects (USED FOR PREDICTED VALUES)
reg gain size_gov size size_squared size_cubed early gov_early gov new2 i.ep_el_n, cluster(ep_el_n)
eststo sone_basic_fe
predict gain_predict
outreg2 using "Table1.xls", dec(3) addstat(`r2_a')

* Model 3: Model 1, but only for Continuous 8 states (BE,DK,FR,DE,IE,IT,LU,NL)
reg gain size_gov size size_squared size_cubed early gov_early gov new2 ///
if continuous_8==1, cluster(ep_el_n)
eststo sone_basic_continuous8
outreg2 using "Table1.xls", dec(3) addstat(`r2_a')

* Model 4: Model 3 plus EP election fixed effects
reg gain size_gov size size_squared size_cubed early gov_early gov new2 i.ep_el_n ///
if continuous_8==1, cluster(ep_el_n)
eststo sone_basic_continuous8_fe
outreg2 using "Table1.xls", dec(3) addstat(`r2_a')

* Model 5: Model 1, but only for CEEC 11 states (BG,HR,CZ,EE,HU,LV,LT,PL,RO,SK,SI)
reg gain size_gov size size_squared size_cubed early gov_early new2 gov ///
if ceec==1, cluster(ep_el_n)
eststo sone_basic_ceec
outreg2 using "Table1.xls", dec(3) addstat(`r2_a')

* Model 6: Model 5 plus EP election fixed effects
reg gain size_gov size size_squared size_cubed early gov_early gov new2 i.ep_el_n  ///
if ceec==1, cluster(ep_el_n)
eststo sone_basic_ceec_fe
outreg2 using "Table1.xls", dec(3) addstat(`r2_a')


****************************************************************
** TABLE A1: Table 1 models with continuous measure of distance since last election
****************************************************************

* Model 1: pooled for all states, no EP election fixed effects
reg gain size_gov size size_squared size_cubed mths_prev_squared gov_mths_squared gov new2, cluster(ep_el_n)
eststo sone_basic
outreg2 using "TableA1.xls", dec(3) addstat(`r2_a')

* Model 2: Model 1 plus EP election fixed effects
reg gain size_gov size size_squared size_cubed mths_prev_squared gov_mths_squared gov new2 i.ep_el_n, cluster(ep_el_n)
eststo sone_basic_fe
outreg2 using "TableA1.xls", dec(3) addstat(`r2_a')

* Model 3: Model 1, but just for Continuous 8 states (BE,DK,FR,DE,IE,IT,LU,NL)
reg gain size_gov size size_squared size_cubed mths_prev_squared gov_mths_squared gov new2 ///
if continuous_8==1, cluster(ep_el_n)
eststo sone_basic_continuous8
outreg2 using "TableA1.xls", dec(3) addstat(`r2_a')

* Model 4: Model 3 plus EP election fixed effects
reg gain size_gov size size_squared size_cubed mths_prev_squared gov_mths_squared gov new2 i.ep_el_n ///
if continuous_8==1, cluster(ep_el_n)
eststo sone_basic_continuous8_fe
outreg2 using "TableA1.xls", dec(3) addstat(`r2_a')

* Model 5: Model 1, but just for CEEC 11 states (BG,HR,CZ,EE,HU,LV,LT,PL,RO,SK,SI)
reg gain size_gov size size_squared size_cubed mths_prev_squared gov_mths_squared new2 gov ///
if ceec==1, cluster(ep_el_n)
eststo sone_basic_ceec
outreg2 using "TableA1.xls", dec(3) addstat(`r2_a')

* Model 6: Model 5 plus EP election fixed effects
reg gain size_gov size size_squared size_cubed mths_prev_squared gov_mths_squared gov new2 i.ep_el_n  ///
if ceec==1, cluster(ep_el_n)
eststo sone_basic_ceec_fe
outreg2 using "TableA1.xls", dec(3) addstat(`r2_a')


****************************************************************
* Table 2: Election by election (with all member states)
****************************************************************

* Model 1: 1979
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep1==1
eststo sone_ep1
outreg2 using "Table2.xls", dec(3) addstat(`r2_a')

* Model 2: 1984
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep2==1
eststo sone_ep2
outreg2 using "Table2.xls", dec(3) addstat(`r2_a')

* Model 3: 1989
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep3==1
eststo sone_ep3
outreg2 using "Table2.xls", dec(3) addstat(`r2_a')

* Model 4: 1994
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep4==1
eststo sone_ep4
outreg2 using "Table2.xls", dec(3) addstat(`r2_a')

* Model 5: 1999
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep5==1
eststo sone_ep5
outreg2 using "Table2.xls", dec(3) addstat(`r2_a')

* Model 6: 2004
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep6==1
eststo sone_ep6
outreg2 using "Table2.xls", dec(3) addstat(`r2_a')

* Model 7: 2009
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep7==1
eststo sone_ep7
outreg2 using "Table2.xls", dec(3) addstat(`r2_a')

* Model 8: 2014
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep8==1
eststo sone_ep8
outreg2 using "Table2.xls", dec(3) addstat(`r2_a')

* Model 9: 2019
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep9==1
eststo sone_ep9
outreg2 using "Table2.xls", dec(3) addstat(`r2_a')

* Model 10: 2024
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep10==1
eststo sone_ep10
outreg2 using "Table2.xls", dec(3) addstat(`r2_a')


****************************************************************
** TABLE A2: Election by election for only Continuous 8 states (i.e. no composition change)
****************************************************************

* Model 1: 1979
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep1==1 & continuous_8==1
eststo sone_ep1_cont
outreg2 using "TableA2.xls", dec(3) addstat(`r2_a')

* Model 2: 1984
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep2==1 & continuous_8==1
eststo sone_ep2_cont
outreg2 using "TableA2.xls", dec(3) addstat(`r2_a')

* Model 3: 1989
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep3==1 & continuous_8==1
eststo sone_ep3_cont
outreg2 using "TableA2.xls", dec(3) addstat(`r2_a')

* Model 4: 1994
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep4==1 & continuous_8==1
eststo sone_ep4_cont
outreg2 using "TableA2.xls", dec(3) addstat(`r2_a')

* Model 5: 1999
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep5==1 & continuous_8==1
eststo sone_ep5_cont
outreg2 using "TableA2.xls", dec(3) addstat(`r2_a')

* Model 6: 2004
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep6==1 & continuous_8==1
eststo sone_ep6_cont
outreg2 using "TableA2.xls", dec(3) addstat(`r2_a')

* Model 7: 2009
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep7==1 & continuous_8==1
eststo sone_ep7_cont
outreg2 using "TableA2.xls", dec(3) addstat(`r2_a')

* Model 8: 2014
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep8==1 & continuous_8==1
eststo sone_ep8_cont
outreg2 using "TableA2.xls", dec(3) addstat(`r2_a')

* Model 9: 2019
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep9==1 & continuous_8==1
eststo sone_ep9_cont
outreg2 using "TableA2.xls", dec(3) addstat(`r2_a')

* Model 10: 2024
reg gain size_gov size size_squared size_cubed early gov_early gov new2 if ep10==1 & continuous_8==1
eststo sone_ep10_cont
outreg2 using "TableA2.xls", dec(3) addstat(`r2_a')


****************************************************************
* Figure 1. Plot of average SONE effects vs. 2024
****************************************************************

twoway (scatter vge_ep_ch vge_prev_parlgov if gov==1) (scatter vge_ep_ch vge_prev_parlgov if gov==0) ///
(qfitci vge_ep_ch vge_prev_parlgov if gov==1) (qfitci vge_ep_ch vge_prev_parlgov if gov==0), ///
scheme(gg_ptol) legend(off) xtitle("Vote share (%) in previous national election") ///
ytitle("Vote share gain (%) in European Parliament election") ///
title("Average second-order effects, 1979-2024")
graph save Figure1-A.gph, replace

twoway (scatter vge_ep_ch vge_prev_parlgov if gov==1 & ep10==1) (scatter vge_ep_ch vge_prev_parlgov if gov==0 & ep10==1) ///
(qfitci vge_ep_ch vge_prev_parlgov if gov==1 & ep10==1) (qfitci vge_ep_ch vge_prev_parlgov if gov==0 & ep10==1), ///
scheme(gg_ptol) legend(off) xtitle("Vote share (%) in previous national election") ///
ytitle("Vote share gain (%) in European Parliament election") ///
title("Second-order effects in 2024")
graph save Figure1-B.gph, replace

graph combine Figure1-A.gph Figure1-B.gph, scheme(gg_ptol) 
erase Figure1-A.gph
erase Figure1-B.gph
graph save "Figure1.gph", replace
graph export "Figure1.pdf", as(pdf) replace


****************************************************************
* Figure 2. Plot of government and opposition parties in 2024, by member state
****************************************************************

graph bar (mean) gov_2024 (mean) opp_2024 if country_n<28, over(country_n, ///
relabel(1 "Aus" 2 "Bel" 3 "Bul" 4 "Cro" 5 "Cyp" 6 "Cze" 7 "Den" 8 "Est" 9 "Fin" 10 "Fra" 11 "Ger" 12 "Gre" 13 "Hun" 14 "Ire" 15 "Ita" 16 "Lat" 17 "Lit" 18 "Lux" 19 "Mal" 20 "Net" 21 "Pol" 22 "Por" 23 "Rom" 24 "Slk" 25 "Sln" 26 "Spa" 27 "Swe") label(angle (forty_five))) ///
scheme(gg_ptol) legend(order(1 "Government 2024" 2 "Opposition 2024") rows(1) position(6)) ylabel(-12(2)10) 
graph save "Figure2.gph", replace
graph export "Figure2.pdf", as(pdf) replace


****************************************************************
* Table 3: Effect of national contexts (with simple size variable)
****************************************************************

* Model 1: Basic model for 2024 election
reg gain size_gov size early gov_early gov new2 if ep10==1
outreg2 using "Table3.xls", dec(3) addstat(`r2_a')

* Model 2: Model 1, for only pro-EP national context
reg gain size_gov size early gov_early gov new2 if ep10==1 & pro_ep==1
outreg2 using "Table3.xls", dec(3) addstat(`r2_a')

* Model 3: Model 1, for only anti-EP national contexnt
reg gain size_gov size early gov_early gov new2 if ep10==1 & pro_ep==0
outreg2 using "Table3.xls", dec(3) addstat(`r2_a')

* Model 4: Model 1, for only single-bloc government national context
reg gain size_gov size early gov_early gov new2 if ep10==1 & rotation==1
outreg2 using "Table3.xls", dec(3) addstat(`r2_a')

* Model 5: Model 1, for only coalition government national context
reg gain size_gov size early gov_early gov new2 if ep10==1 & rotation==0
outreg2 using "Table3.xls", dec(3) addstat(`r2_a')

* Model 6: Model 1, for only high ENPV national context
reg gain size_gov size early gov_early gov new2 if ep10==1 & high_enpv==1
outreg2 using "Table3.xls", dec(3) addstat(`r2_a')

* Model 7: Model 1, for only low ENPV national context
reg gain size_gov size early gov_early gov new2 if ep10==1 & high_enpv==0
outreg2 using "Table3.xls", dec(3) addstat(`r2_a')


******************************************
* Table 4: Party family effects
******************************************

*drop IND & REG
drop if family=="IND"
drop if family=="REG"

* nb1. ANTI & RIGHT families combined
* nb2. Baseline in the models = Liberal family
* nb3. Table A3 shows the full results from these models

* Model 1: Basic party family effects model, with no SONE effects
reg gain left grn soc cdem con anti_right i.ep_el_n, cluster(ep_el_n)
outreg2 using "Table4.xls", dec(3) addstat(`r2_a')

* Model 2: Model 1, for only Continuous 8 states
reg gain left grn soc cdem con anti_right i.ep_el_n ///
if continuous_8==1, cluster(ep_el_n)
outreg2 using "Table4.xls", dec(3) addstat(`r2_a')

* Model 3: Model 1, for only CEEC 11 states
reg gain left grn soc cdem con anti_right i.ep_el_n  ///
if ceec==1, cluster(ep_el_n)
outreg2 using "Table4.xls", dec(3) addstat(`r2_a')

* Model 4: Basic party family effects model (Model 1) PLUS SONE effects
reg gain size_gov size size_squared size_cubed early gov_early gov new2 ///
left grn soc cdem con anti_right i.ep_el_n, cluster(ep_el_n)
outreg2 using "Table4.xls", dec(3) addstat(`r2_a')

* Model 5: Model 4, for only Continuous 8 states
reg gain size_gov size size_squared size_cubed early gov_early gov new2 ///
left grn soc cdem con anti_right i.ep_el_n ///
if continuous_8==1, cluster(ep_el_n)
outreg2 using "Table4.xls", dec(3) addstat(`r2_a')

* Model 6: Model 4, for only CEEC 11 states
reg gain size_gov size size_squared size_cubed early gov_early gov new2 ///
left grn soc cdem con anti_right i.ep_el_n  ///
if ceec==1, cluster(ep_el_n)
outreg2 using "Table4.xls", dec(3) addstat(`r2_a')


******************************************
* Figure 3: Party family effects over time
******************************************

twoway (lpolyci gain_predict year_ep if left==1, lcolor(maroon) alcolor(white)) ///
(lpoly gain year_ep if left==1, lcolor(blue)), title("Radical Left", size(small)) ///
scheme(gg_ptol) legend(off) ylabel(-6(2)4) xlabel(1979(5)2024, angle(forty_five)) ///
xscale(alt) fysize(58) fxsize(60) ///
ytitle("Vote share gain (%) in EP election") xtitle("")
graph save Figure3-A.gph, replace

twoway (lpolyci gain_predict year_ep if grn==1, lcolor(maroon) alcolor(white)) ///
(lpoly gain year_ep if grn==1, lcolor(blue)), title("Green", size(small)) ///
scheme(gg_ptol) legend(off) ylabel(-6(2)4) xlabel(1979(5)2024, angle(forty_five)) ///
xscale(alt) yscale(off) fysize(58) fxsize(48) ///
ytitle("Vote share gain (%) in EP election") xtitle("")
graph save Figure3-B.gph, replace

twoway (lpolyci gain_predict year_ep if soc==1, lcolor(maroon) alcolor(white)) ///
(lpoly gain year_ep if soc==1, lcolor(blue)), title("Social Democrat", size(small)) ///
scheme(gg_ptol) legend(off) ylabel(-6(2)4) xlabel(1979(5)2024, angle(forty_five)) ///
xscale(alt) yscale(off) fysize(58) fxsize(48) ///
ytitle("Vote share gain (%) in EP election") xtitle("")
graph save Figure3-C.gph, replace

twoway (lpolyci gain_predict year_ep if lib==1, lcolor(maroon) alcolor(white)) ///
(lpoly gain year_ep if lib==1, lcolor(blue)), title("Liberal", size(small)) ///
scheme(gg_ptol) legend(off) ylabel(-6(2)4) xlabel(1979(5)2024, angle(forty_five)) ///
xscale(alt) yscale(off) fysize(58) fxsize(48) ///
ytitle("Vote share gain (%) in EP election") xtitle("")
graph save Figure3-D.gph, replace

twoway (lpolyci gain_predict year_ep if cdem==1, lcolor(maroon) alcolor(white)) ///
(lpoly gain year_ep if cdem==1, lcolor(blue)), title("Christian Democrat", size(small)) ///
scheme(gg_ptol) legend(off) ylabel(-6(2)4) xlabel(1979(5)2024, angle(forty_five)) ///
fysize(58) fxsize(60) ///
ytitle("Vote share gain (%) in EP election") xtitle("")
graph save Figure3-E.gph, replace

twoway (lpolyci gain_predict year_ep if con==1, lcolor(maroon) alcolor(white)) ///
(lpoly gain year_ep if con==1, lcolor(blue)), title("Conservative", size(small)) ///
scheme(gg_ptol) legend(off) ylabel(-6(2)4) xlabel(1979(5)2024, angle(forty_five)) ///
yscale(off) fysize(58) fxsize(48) ///
ytitle("Vote share gain (%) in EP election") xtitle("")
graph save Figure3-F.gph, replace

twoway (lpolyci gain_predict year_ep if anti_right==1, lcolor(maroon) alcolor(white)) ///
(lpoly gain year_ep if anti_right==1, lcolor(blue)), title("Anti EU+Radical Right", size(small)) ///
scheme(gg_ptol) legend(off) ylabel(-6(2)4) xlabel(1979(5)2024, angle(forty_five)) ///
yscale(off) fysize(58) fxsize(48) ///
ytitle("Vote share gain (%) in EP election") xtitle("")
graph save Figure3-G.gph, replace

graph combine Figure3-A.gph Figure3-B.gph Figure3-C.gph Figure3-D.gph ///
Figure3-E.gph Figure3-F.gph Figure3-G.gph, scheme(gg_ptol) rows(2) ycommon xcommon
*graph save "Figure3.gph", replace
*graph export "Figure3.pdf", as(pdf) replace
*note(order(1 "Average vote gain" 2 "Predicted vote gain (SONE)") rows(1) position(6))
erase Figure3-A.gph
erase Figure3-B.gph
erase Figure3-C.gph
erase Figure3-D.gph
erase Figure3-E.gph
erase Figure3-F.gph
erase Figure3-G.gph


log close
